﻿using System;
using System.Data;
using DevExpress.XtraEditors;
using PMS.BLL;
using PMS.Entity;
using PMS.Resources;
using PMS.Win;
using PMS.Utils;
using CrystalDecisions.CrystalReports.Engine;
using PMS.Report;
using CrystalDecisions.Shared;

namespace PMS.ReportViewer
{
    public partial class ChiTietXuatSanPhamViewer : BaseForm
    {
        public ChiTietXuatSanPhamViewer()
        {
            InitializeComponent();
        }

        public ChiTietXuatSanPhamViewer(string MaSP, DateTime? tungay, DateTime? denngay)
        {
            InitializeComponent();
            ReportBO rp = new ReportBO();
            ReportClass r = new ChiTietXuatSanPham();
            DataSet ds = rp.ChiTietXuatSanPham(MaSP, tungay, denngay);
            r.SetDataSource(ds);
            crystalReportViewer1.ReportSource = r;
            crystalReportViewer1.ParameterFieldInfo.Add(CreateParameter("TuNgay", (tungay == null) ? "" : ((DateTime)tungay).ToShortDateString()));
            crystalReportViewer1.ParameterFieldInfo.Add(CreateParameter("DenNgay", (denngay == null) ? "" : ((DateTime)denngay).ToShortDateString()));        
        }

        private ParameterField CreateParameter(string name, object value)
        {
            // create a new parameter with the same name as the one you used in your report designer.
            // Setup the parameter field and value for the report
            ParameterDiscreteValue pVal = new ParameterDiscreteValue();
            pVal.Value = value; // Set the parameter value
            ParameterField pField = new ParameterField(); //Create a new parameter field to hold the value.
            pField.Name = name; // Use the same parameter field name that you used in the report design.
            pField.CurrentValues.Add(pVal); // Add the value to the field.
            pField.HasCurrentValue = true; // This tells the parameter not to prompt because it already has a value.
            return pField;
        }
    }
}